<?php include $this->admin_tpl('meta');?>
<title>添加字段 - YzmCMS内容管理系统</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 内容管理 <span class="c-gray en">&gt;</span> 字段管理 <span class="c-gray en">&gt;</span> 添加字段 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<article class="page-container">
<div class="formdoby_info"> 
	  <fieldset>
		<legend><?php echo $modelname ?></legend>
		    <form action="" method="post" onsubmit="return check_all()">
			<table class="table table-border yzmcms_table">			
				<tr>
					<td width="180"><span class="c-red">*</span>字段类型</td> 
					<td>
					<span class="select-box inline">
					<select name="fieldtype" id="fieldtype" class="select" onchange="javascript:field_setting(this.value);">
					<option value='0' selected>请选择字段类型</option>
					<option value="input" >单行文本</option>
					<option value="textarea" >多行文本</option>
					<option value="number" >整数类型</option>
					<option value="datetime" >时间类型</option>
					<option value="image" >图片上传</option>					
					<option value="images" >多图片上传</option>					
					<option value="attachment" >附件上传</option>					
					<option value="attachments" >多附件上传</option>					
					<option value="select" >option下拉框</option>
					<option value="radio" >radio选项卡</option>
					<option value="checkbox" >checkbox多选框</option>
					<option value="editor" >编辑器</option>
					<option value="editor_mini" >编辑器(Mini版)</option>
					</select>
					</span>
                    </td>
				</tr>
				<tr>
					<td><span class="c-red">*</span>字段名</td> 
					<td><input type="text" name="field" value="" class="input-text w_300" id="field" onblur="check_field()"><span class="tip">只能由英文字母、数字和下划线组成，例如：name</span></td>
				</tr>
				<tr>
					<td><span class="c-red">*</span>字段别名</td> 
					<td><input type="text" name="name" value="" class="input-text w_300" id="name" onblur="check_name()"><span class="tip">例如：姓名</span></td>
				</tr>				
				<tr>
					<td>字段提示</td> 
					<td><input type="text" name="tips"  class="input-text w_300"><span class="c-red"></span><span class="tip">显示在字段别名下方作为表单输入提示</span></td>
				</tr>
				<tr style="display:none" id="options">
					<td>选项列表</td> 
					<td><textarea style="height:100px;width:400px;float:left;margin-right:5px" name="setting" id="textarea" class="textarea"></textarea><span style="color:#888">多个选项用 “|” 分开，如：<br>男|女|未知<br><i class="mt-5" style="display:block;">也支持自定义key值，如：<br>0:男|1:女|2:未知</i></span></td>
				</tr>	
				<tr style="display:none" id="dates">
					<td>时间格式</td> 
					<td> 
					 <label><input type="radio" name="dateset" value="0" checked> 日期（<?php echo date('Y-m-d')?>）</label>
					 <br><label><input type="radio" name="dateset" value="1"> 日期+时间（<?php echo date('Y-m-d H:i:s')?>）</label>
					</td>
				</tr>				
				<tr>
					<td>默认值</td> 
					<td><input class="input-text w_300" type="text" value="" name="defaultvalue"></td>
				</tr>				
				<tr>
					<td>字符长度取值范围</td> 
					<td class="yzm-explain-box">最小值：<input class="input-text w_120" type="text" value="0" name="minlength">
                        最大值：<input class="input-text w_120" type="text" value="100" name="maxlength">
                        <span class="yzm-explain">最小值为1则为必填项，为0则非必填项</span>
                    </td>
				</tr>	
				<tr>
					<td>数据校验未通过的提示信息</td> 
					<td><input type="text" name="errortips" value="" class="input-text w_300"></td>
				</tr>	
				<tr>
					<td>在会员投稿中显示</td> 
					<td>
					 <label><input type="radio" name="isadd" value="1"> 是</label>
					 &nbsp;&nbsp;<label><input type="radio" name="isadd" value="0" checked> 否</label>
					</td>
				</tr>				
				<tr>
					<td>禁用</td> 
					<td>
					 <label><input type="radio" name="disabled" value="1"> 是</label>
					 &nbsp;&nbsp;<label><input type="radio" name="disabled" value="0" checked> 否</label>
					</td>
				</tr>				
                <tr>
					<td></td>
					<td>
					<input class="dosubmit w_120 btn-primary radius" name="dosubmit" type="submit" value="提交">
					<input class="btn w_120 btn-default radius h35" type="button" value="后退" onclick="window.history.go(-1)">
					</td>
				</tr>				
			</table>
            </form>			
	  </fieldset>
</div>
</article>
<?php include $this->admin_tpl('footer');?> 
<script type="text/javascript">
	function field_setting(fieldtype) {
	    if(fieldtype=='select' || fieldtype=='radio' || fieldtype=='checkbox') {
			$('#options').css('display','');
		}else{
			$('#options').css('display','none');
		} 
	    if(fieldtype=='datetime') {
			$('#dates').css('display','');
		}else{
			$('#dates').css('display','none');
		} 		
	}

	function check_name(){ 
		if($("input[name='name']").val()==''){
			layer.msg('字段别名不能为空！');
			return false;
		}else{
			return true;
		}		
	}
	
	function check_field(){ 
       var res = false;	
       var reg = /^[a-zA-Z]{1}([a-zA-Z0-9]|[_]){0,19}$/;	
       if(!reg.test($("input[name='field']").val())){
		   layer.msg('字段名不正确！');
		   return false;
		}
		
		$.ajax({   
		type: "get",   
		url: '<?php echo U('public_check_field');?>',   
		dataType: "html",
		async:false,
		data: "field="+$('#field').val()+"&modelid=<?php echo intval($_GET['modelid']);?>",   
		success: function(msg){
		if(msg){
			if(msg==0){
				layer.msg('字段名已经存在！');
			}else if(msg==1){
				res = true;	
			}else{
				layer.alert('Ajax通信失败！');
			}
		}  
		}  
		});
        return res;		
	}
	
	function check_all(){
		var fieldtype = $("select[name='fieldtype']").val();
	    if(fieldtype =='0'){
		   layer.msg('请选择字段类型！');
		   return false;
		}else if(fieldtype=='select' || fieldtype=='radio' || fieldtype=='checkbox'){
			if($('#textarea').val() == ''){
				layer.msg('选项列表不能为空！');
				return false;
			}
		}
		
	    if(!check_field() || !check_name()){
		    return false;
		}
		
	    if(isNaN($("input[name='minlength']").val()) || isNaN($("input[name='maxlength']").val())){
		    layer.msg('字符长度取值范围 只能为数字类型！');
		    return false;
		}		
        return true;			
	}
</script> 
</body>
</html>